package learn_concurrent._6;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class T4 {
	static final Logger logger = LoggerFactory.getLogger(T4.class);

	static final Object lock = new Object();
	
	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread(() -> {
			synchronized (lock) {
				logger.info("running...");
				try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				logger.info("other work...");
			}
		}, "t1");
		t1.start();
		
		Thread t2 = new Thread(() -> {
			synchronized (lock) {
				logger.info("running...");
				try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				logger.info("other work...");
			}
		}, "t2");
		t2.start();
		
		Thread.sleep(1000);
		logger.info("t1 status : {}", t1.getState());
		logger.info("t2 status : {}", t2.getState());
		
		synchronized (lock) {
			lock.notifyAll();
			logger.info("noity -> t1 status : {}", t1.getState());
			logger.info("noity -> t2 status : {}", t2.getState());
		}
		logger.info("final -> t1 status : {}", t1.getState());
		logger.info("final -> t2 status : {}", t2.getState());
	}

}
